<?php
/**
 * Created by PhpStorm.
 * User: alice
 * Date: 2015/12/28
 * Time: 12:26
 */

/**
 * Class Involved_ArticleModel
 */

class Involved_InformationModel extends BaseModel{

    protected $table = 'information';

    /**
     * 资讯列表
     * @author alice
     * @date 2016-1-19
     * @return mixed
     */
    public function ShowInformationList()
    {
        $info =  DB::table($this->table)->paginate(8);
        foreach($info as $k => $v)
        {
            $v->created = date('Y-m-d');
        }
        return $info;
    }

    /**
     * 资讯详情
     * @param $id
     * @author alice
     * @date 2016-1-19
     * @return mixed
     */
    public function ShowInformationInfo($id)
    {
        return  DB::table($this->table)->where('zx_id',$id)->first();
    }


    /**
     * 资讯列表
     * @param $paramObj
     * @return array
     * @author fyl
     * @date 2016-8-02
     */
    public function GetInformationList($paramObj)
    {
        $offset = ($paramObj->page-1) * HostEnum::PAGE_NUM;

        $oQuery = DB::table($this->table);

        $list = $oQuery
            ->skip($offset)->take(HostEnum::PAGE_NUM)
            ->select('title','zx_id','thumb_img1','thumb_img2','thumb_img3','created','content','cate')
            ->where('cate',$paramObj->cate)
            ->orderBy('zx_id','desc')
            ->get();

        return $list;

    }

    public function GetInformationDetail($id)
    {
        $info = DB::table($this->table)
            ->where(['zx_id' => $id])
            ->first();

        if (!empty($info)) {
            return $info;
        } else {
            throw new Exception('资讯不存在 ', ProfessionErrorCodeEnum::STATUS_ERROR_PARAMS_MUST);
        }
    }
    /**
     * 获取資訊列表
     * @author fyl
     * @date 2016-04-01
     */
    public function AdminInformationList()
    {
        return DB::table($this->table)
            ->orderBy('created','desc')
            ->get();
    }

    /**
     * 获取首页列表
     * @author fyl
     * @date 2016-04-01
     */
    public function InformationList($type)
    {
        return DB::table($this->table)
            ->select('title','zx_id','thumb_img1','created')
            ->where('cate',$type)
            ->orderBy('created','desc')
            ->take(6)
            ->get();
    }

    /**
     * 根据ID获取资讯详情
     * @return mixed
     */
    public function GetNewsById($id)
    {
        return  DB::table($this->table)
            ->where('information.zx_id',$id)
            ->first();
    }
    //资讯列表
    public function InformationList1($cate){
        return DB::table($this->table)
            ->select('title','zx_id','thumb_img1','thumb_img2','thumb_img3','created','content','cate')
            ->where('cate',$cate)
            ->orderBy('created','desc')
            ->paginate(4);

    }

}